package com.yunkaweilai.android.utils;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

/**
 * Created by Administrator on 2017/6/14.
 */

public class InputMethodUtils {

    public static void closeKey(Context context,EditText view){
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);

    // 获取软键盘的显示状态
            boolean isOpen=imm.isActive();
        Log.e("asd", "closeKey: "+isOpen );
        if (isOpen){
            // 强制隐藏软键盘
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }else{
            // 强制显示软键盘
            imm.showSoftInput(view,InputMethodManager.SHOW_FORCED);
        }
    }



    /**
     * 关闭软键盘
     */
    public static void closeSoftKeyboard(Activity activity) {
        //隐藏软键盘
        View view = activity.getWindow().peekDecorView();
        if (view != null) {
            InputMethodManager inputmanger = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }

}
